<?php
// plugins
$this->headLink()->appendStylesheet('js/extjs-ux/multiselect/multiselect.css');
$this->headScript()->appendFile('js/extjs-ux/multiselect/MultiSelect.js');
$this->headScript()->appendFile('js/extjs-ux/multiselect/DDView.js');

// gui
$this->headScript()->appendFile('js/ecart/admin/customer/index/customer.js')
    ->appendFile('js/ecart/admin/customer/index/customer/combos.js')
    ->appendFile('js/ecart/admin/customer/index/customer/grid.js')
    ->appendFile('js/ecart/admin/customer/index/panel.js')
    ->appendFile('js/ecart/admin/customer/index/customer/addressWindow.js')
    ->appendFile('js/ecart/admin/customer/index/customer/tabs/general.js')
    ->appendFile('js/ecart/admin/customer/index/customer/tabs/customFields.js')
    ->appendFile('js/ecart/admin/customer/index/customer/tabs/address.js')
    ->appendFile('js/ecart/admin/customer/index/customer/tabs/order.js')
    ->appendFile('js/ecart/admin/customer/index/customer/tabs/shoppingCart.js')
    ->appendFile('js/ecart/admin/customer/index/customer/tabs/wishlist.js')
    ->offsetSetFile(10000, 'js/ecart/admin/customer/index/customer/window.js')
    ;

// should be added automatically by modular admin layout system
if (in_array('Ecart_Tag', array_keys(Ecart::app()->getModules()))) {
    $this->headScript()->offsetSetFile(500, 'js/ecart/admin/tag/customer_index/tabs/tag.js');
}
if (in_array('Ecart_Community', array_keys(Ecart::app()->getModules()))) {
    $this->headScript()->offsetSetFile(510, 'js/ecart/admin/community/customer_index/tabs/review.js');
}
?>

<script type="text/javascript">
var customerGroups = [
    <?php
    $str = '';
    foreach (Ecart_Collect_CustomerGroup::collect() as $id => $name) {
        $str .= "[$id, '$name'],\n";
    }

    echo substr($str, 0, -2);
    ?>
];
var sites = [
    <?php
    $str = '';
    foreach (Ecart_Collect_Site::collect() as $id => $name) {
        $str .= "[$id, '$name'],\n";
    }

    echo substr($str, 0, -2);
    ?>
];
var customFormFields = [
<?php
    $fi = "";
    $readerFields = '';
    foreach ($this->userForm as $fs) {
        $fi .=
        "{
            xtype: 'fieldset',
            title: '{$fs['title']}',
            autoHeight: true,
            collapsible: true,
            hidden: " . ($fs['is_active'] ? 'false' : 'true') . ",
            collapsed: " . ($fs['is_active'] ? 'false' : 'true') . ",
            " . $this->fieldsetItems($fs, $this->valueSet) ."
            defaults: {width: 300}
        },\n";
        foreach ($fs['fields'] as $fld) {
            $readerFields .= "{name: 'custom_fields[field_" . $fld['id'] . "]', mapping: 'custom_fields.field_" . $fld['id'] . "'},\n";
        }
    }
    echo substr($fi, 0, -2);
?>];
var customFormReader = [
    <?php echo substr($readerFields, 0, -2); ?>
];

<?php if ($this->customerId) : ?>
Ext.onReady(function() {
    Customer.load(<?php echo $this->customerId ?>);
})
<?php endif; ?>
</script>